//
//  ContactsFailViewController.m
//  
//
//  Created by Dream on 2018/8/2.
//

#import "ContactsFailViewController.h"

@interface ContactsFailViewController ()

@end

#define k16Color(s)     [UIColor colorWithRed:(((s & 0xFF0000) >> 16))/255.0 green:(((s &0xFF00) >>8))/255.0 blue:((s &0xFF))/255.0 alpha:1.0]

@implementation ContactsFailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    self.navigationItem.title = @"通讯录认证";
    self.view.backgroundColor = [UIColor colorWithRed:246/255.0 green:247/255.0 blue:251/255.0 alpha:1.0];
    
    //屏幕宽高
    CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
    CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 260)];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    
    //成功icon
    NSBundle *bundle = [NSBundle bundleForClass:[self class]];
    NSBundle *resourcesBundle = [NSBundle bundleWithPath:[bundle pathForResource:@"ContactsResources" ofType:@"bundle"]];
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_fail" inBundle:resourcesBundle compatibleWithTraitCollection:nil]];
    
    imageView.center = CGPointMake(screenWidth * 0.5, 135);
    [view addSubview:imageView];
    
    //文字
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(imageView.frame) + 20, screenWidth, 30)];
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = [UIFont boldSystemFontOfSize:18.0];
    [view addSubview:titleLabel];
    
    titleLabel.text = @"通讯录认证失败";
    
    //副标题
    UILabel *subLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(titleLabel.frame), screenWidth, 30)];
    subLabel.textColor = k16Color(0x999999);
    subLabel.textAlignment = NSTextAlignmentCenter;
    subLabel.font = [UIFont systemFontOfSize:14.0];
    [view addSubview:subLabel];
    
    subLabel.text = @"未能获取手机通讯录授权";
    
    //提示
    UILabel *tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(view.frame), screenWidth - 30, 60)];
    tipLabel.textColor = k16Color(0x999999);
    tipLabel.font = [UIFont systemFontOfSize:14.0];
    tipLabel.numberOfLines = 0;
    [self.view addSubview:tipLabel];
    
    //行间距
    NSString *string = @"请在iPhone的\"设置-APP-通讯录\"选项中，允许APP访问你的通讯录。";
    
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    
    [paragraphStyle setLineSpacing:6.0];
    [paragraphStyle setAlignment:NSTextAlignmentLeft];
    
    [attrStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attrStr.length)];
    
    tipLabel.attributedText = attrStr;
    
    
    //确认按钮
    UIButton *upButton = [[UIButton alloc] initWithFrame:CGRectMake(15, screenHeight - 100, screenWidth - 30, 44)];
    
    upButton.titleLabel.font = [UIFont systemFontOfSize:14.0];
    [upButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [upButton setTitle:@"完成" forState:UIControlStateNormal];
    
    upButton.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.7];
    
    [upButton addTarget:self action:@selector(doneAction) forControlEvents:UIControlEventTouchUpInside];
    
    upButton.layer.cornerRadius = 22;
    upButton.layer.masksToBounds = YES;
    
    [self.view addSubview:upButton];
}

- (void)doneAction
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
